# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=kernelshark
pkgver=2.2.1
pkgrel=2
pkgdesc="GUI frontend for trace-cmd based Linux kernel Ftrace captures"
arch=(loong64 x86_64)
url="https://kernelshark.org/"
license=(
  GPL-2.0-only
  LGPL-2.0-only
)
depends=(
  freeglut
  gcc-libs
  glibc
  glu
  qt5-base
  ttf-fira-sans
)
makedepends=(
  boost
  cmake
  json-c
  libglvnd
  libtracefs
  libtraceevent
  trace-cmd
)
optdepends=(
  'bash: for kshark-su-record'
)
provides=(
  libkshark.so
  libkshark-plot.so
  libkshark-gui.so
)
source=($pkgname-$pkgver.tar.gz::https://git.kernel.org/pub/scm/utils/trace-cmd/kernel-shark.git/snapshot/kernel-shark-$pkgname-v$pkgver.tar.gz)
sha512sums=('1e0b17de02b82a20f6f78ebbfe61c63550947c3275e1262ae6edfd4675f7d1f976955ed37b14f2a214675a83e43135e605c244b4a5f920ebcdeaabcda7510d10')
b2sums=('a11e61660cbf98bbbb7c5060014b4de8e05f6957f2eb5519c3a109d91e5297a4532af3c958471ab181ddc8cbb061d1a493b3f40b71efb3abe3d47640a4ab87cc')

prepare() {
  cd kernel-shark-$pkgname-v$pkgver

  # replace FreeSans with ttf-fira-sans
  sed -e 's/FreeSans/FiraSans-Regular/g' \
      -i CMakeLists.txt
}

build() {
  local cmake_options=(
    -B build
    -D_INSTALL_PREFIX=/usr
    -D_LIBDIR=/usr/lib
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -S kernel-shark-$pkgname-v$pkgver
    -Wno-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

package() {
  depends+=(
    json-c libjson-c.so
    libglvnd libGL.so
    libtraceevent libtraceevent.so
    libtracefs libtracefs.so
    trace-cmd libtracecmd.so
  )

  DESTDIR="$pkgdir" cmake --install build
}
